from PySide6.QtCore import QUrl, Qt
from PySide6.QtGui import QFont  # 导入QFont
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel, QFileDialog, QHBoxLayout
from qfluentwidgets import FluentIcon, PushButton
from qfluentwidgets.multimedia import VideoWidget


class VideoInterface(QWidget):
    def __init__(self):
        super().__init__()
        from PySide6.QtMultimedia import QMediaPlayer

        self.player = QMediaPlayer()
        self.setObjectName("video_interface")
        self.setWindowTitle("Fluent Video Player")
        self.resize(900, 600)

        # 设置主题
        # setTheme(Theme.DARK)

        # 创建主布局
        self.main_layout = QVBoxLayout(self)
        self.main_layout.setContentsMargins(20, 50, 20, 20)
        self.main_layout.setSpacing(15)

        # 创建标题标签 - 修复字体设置
        self.title_label = QLabel("Fluent Video Player")
        self.title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        # 正确设置字体：使用QFont.Bold表示粗体
        title_font = QFont()
        title_font.setPointSize(24)
        title_font.setBold(True)  # 使用setBold方法设置粗体
        self.title_label.setFont(title_font)

        self.main_layout.addWidget(self.title_label)

        # 创建视频播放器
        self.video_widget = VideoWidget()
        self.video_widget.setMinimumHeight(400)
        self.main_layout.addWidget(self.video_widget, 1)

        # 创建控制面板
        self.control_layout = QHBoxLayout()
        self.control_layout.setContentsMargins(10, 10, 10, 10)
        self.control_layout.setSpacing(15)
        self.main_layout.addLayout(self.control_layout)

        # 添加控制按钮
        self.open_button = PushButton(FluentIcon.FOLDER_ADD, "打开视频")
        self.open_button.setFixedWidth(120)
        self.open_button.clicked.connect(self.open_video)
        self.control_layout.addWidget(self.open_button)

        # 添加状态标签 - 修复字体设置
        self.status_label = QLabel("准备就绪")
        self.status_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        status_font = QFont()
        status_font.setPointSize(12)
        self.status_label.setFont(status_font)
        self.control_layout.addWidget(self.status_label)

        # 设置初始状态
        self.video_loaded = False
        self.is_fullscreen = False

        # 设置样式
        # self.setStyleSheet("""
        #     QWidget {
        #         background-color: #2b2b2b;
        #         color: #f0f0f0;
        #     }
        #     QLabel {
        #         padding: 5px;
        #     }
        # """)

    def open_video(self):
        """打开视频文件"""
        file_path, _ = QFileDialog.getOpenFileName(
            self,
            "选择视频文件",
            "",
            "视频文件 (*.mp4 *.avi *.mkv *.mov *.flv *.wmv);;所有文件 (*.*)",
        )

        if file_path:
            # 设置视频URL
            self.video_widget.setVideo(QUrl.fromLocalFile(file_path))
            self.status_label.setText(f"已加载视频: {file_path.split('/')[-1]}")
            self.video_loaded = True

    def play_video(self):
        """播放视频"""
        if self.video_loaded:
            self.video_widget.play()
            self.status_label.setText("正在播放...")

    def pause_video(self):
        """暂停视频"""
        if self.video_loaded:
            self.video_widget.pause()
            self.status_label.setText("已暂停")

    def stop_video(self):
        """停止视频"""
        if self.video_loaded:
            self.video_widget.stop()
            self.status_label.setText("已停止")

    def toggle_fullscreen(self):
        """切换全屏模式"""
        if self.is_fullscreen:
            self.showNormal()
        else:
            self.showFullScreen()
            self.is_fullscreen = True


# if __name__ == "__main__":
#     app = QApplication(sys.argv)

#     # 设置应用程序样式
#     from qfluentwidgets import setThemeColor
#     setThemeColor('#28a9e0')

#     player = VideoPlayer()
#     player.show()
#     sys.exit(app.exec())
